#!/bin/bash

SVN_REPO_DIR="svnRepo"
SVN_PORT="9595"
SVN_USER="svn_user"
SVN_PASSWORD="cru1s3"

PORT_OCCUPIED=`netstat -na|grep $SVN_PORT`

if [ ! -d $SVN_REPO_DIR ] && [ -z $PORT_OCCUPIED ]
then
	echo "folder $SVN_REPO_DIR will be created under which a svn repo will be setup via svnadmin and svnserv."
	svnadmin create $SVN_REPO_DIR
	cd $SVN_REPO_DIR
	svnserve -d --listen-port $SVN_PORT
	echo "$SVN_USER = $SVN_PASSWORD" >> conf/passwd
	echo "anon-access = read" >> conf/svnserve.conf
	echo "auth-access = read" >> conf/svnserve.conf
	echo "auth-access = write" >> conf/svnserve.conf
	echo "password-db = passwd" >> conf/svnserve.conf
	echo "svn repo svn://$HOSTNAME:$SVN_PORT$PWD is setup."
	URL="svn://$HOSTNAME:$SVN_PORT$PWD" 
	cd ..
	echo "the svn url is $URL"
	echo "current path is $PWD" 
	svn --username $SVN_USER --password $SVN_PASSWORD --non-interactive co $URL svnlocalrepo
	cd svnlocalrepo
	touch svninit.txt
	svn add *
	svn --username $SVN_USER --password $SVN_PASSWORD ci -m "checkin initfile" 
else
	echo "Folder $SVN_REPO_DIR already exists or port $SVN_PORT is occupied. Please check your environment first."
fi
